<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!doctype html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>LoveTemperature</title>
		<meta name="author" content="ningzero"/>

		<!-- CSS -->
		<link rel="stylesheet" href="../css/cart_step2.css">
		<link rel="stylesheet" href="../css/jquery-ui.min.css">
		<!-- end CSS-->

	</head>

	<body>

		<div id="container">
			<header class="header">
				<div id="login_cart_bar">
					<div id="loginRegisterDiv">
						欢迎惠顾，<s:property value="#session.user.name" />
						<a class="pinkAnchor" href="http://localhost:8080/lovetemperature/sale/logout">退出登录</a>
					</div>
					<div id="cartAccountDiv">
						<a class="pinkAnchor" onclick="javascript:window.location='http://localhost:8080/lovetemperature/sale/showStepOne'">购物车</a>
						<a class="pinkAnchor" onclick="javascript:window.location='http://localhost:8080/lovetemperature/sale/showMember'">我的账户</a>
					</div>
				</div>
				<div id="logo_bar">
					<img src="../img/logo.gif"/>
					<img id="logo_text" src="../img/logo2.png"/>
				</div>
				<div id="nav_bar">
					<ul>
						<li class="nav_padding_left"></li>
						<li class='<s:if test="%{#showCategory=='首页'}">shouye_cur</s:if><s:else>shouye</s:else>'>
							<a href="http://localhost:8080/lovetemperature/index">首页</a>
						</li>
						<li class='<s:if test="%{#showCategory=='蛋糕'}">dangao_cur</s:if><s:else>dangao</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=蛋糕">蛋糕</a>
						</li>
						<li class='<s:if test="%{#showCategory=='面包'}">mianbao_cur</s:if><s:else>mianbao</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=面包">面包</a>
						</li>
						<li class='<s:if test="%{#showCategory=='干点'}">gandian_cur</s:if><s:else>gandian</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=干点">干点</a>
						</li>
						<li class='<s:if test="%{#showCategory=='拌手礼'}">banshouli_cur</s:if><s:else>banshouli</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=拌手礼">伴手礼</a>
						</li>
						<li class='<s:if test="%{#showCategory=='饮品'}">kaquan_cur</s:if><s:else>kaquan</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=饮品">饮品</a>
						</li>
						<li class='<s:if test="%{#showCategory=='其他'}">qita_cur</s:if><s:else>qita</s:else>'>
							<a href="http://localhost:8080/lovetemperature/sale/index?category=其他">其他</a>
						</li>
					</ul>
				</div>
			</header>
			<div id="mainContent" class="mainContent">
				<div id="cartNavBar">
					<div id="cartNavStepBar"></div>
					<div id="cartNavCartImg"></div>
				</div>
				<s:form action="http://localhost:8080/lovetemperature/sale/submitCart" id="form">
				<div id="userInfoDiv">
					<div class="pinkSplit">
						<h4>请确认　收货人信息</h4>
					</div>
					<p>　　姓名：<input name="name" type="text" zhname="姓名" id="name" value='<s:property value="#member.name" />'/></p>
					<p>联系电话：<input name="phone" type="text" zhname="联系电话" id="phone" value='<s:property value="#member.phone" />'/></p>
				</div>
				<div id="payMethodDiv">
					<div class="pinkSplit">
						<h4>请选择　付款方式</h4>
					</div>
					<p><input type="radio" name="payMethod" value="bank"/>	网上银行全额支付</p>
					<p><input type="radio" name="payMethod" value="zhifubao"/>	会员账户支付</p>	
				</div>
				
				</s:form>
				<div id="goodsListDiv">
					<table id="goodsListTable">
						<thead>
							<tr>
								<th>商品名称</th>
								<th>单价</th>
								<th>数量</th>
								<th>小计</th>
							</tr>
						</thead>
						<tbody>
							<!-- 购物车中一件商品begin -->
							<s:iterator value="curGoodSetList" status="st">
							<tr>
								<td class="cartName"><s:property value="good.name"/></td>
								<td class="cartPrice" id='price_<s:property value="#st.index"/>'>￥<s:property value="good.price"/></td>
								<td class="cartCount"><span id='input_<s:property value="#st.index"/>' ><s:property value="count"/></span></td>
								<td class="cartTotalPrice" id='totalPrice_<s:property value="#st.index"/>'></td>
							</tr>
							</s:iterator>
							<!-- 购物车中一件商品end -->
						</tbody>
					</table>
				</div>
				<div id="payDiv">
					<span>商品总额：</span><span class="price" id="totalPrice"></span>
					<div class="normalBtn" onclick="submit()">确认订单，付款</div>
				</div>
			</div>
		</div>
		<!--! end of #container -->
		
		<footer id="footer">
			<img src="../img/tmp/tmpfooter.png" />
		</footer>

		<!-- scripts -->
		<script type="text/javascript" src="../js/libs/jquery-1.9.1.min.js" ></script>
		<script type="text/javascript" src="../js/libs/jquery-ui.min.js" ></script>
		<script type="text/javascript" src="../js/libs/jquery.ui.datepicker.js" ></script>
		<script type="text/javascript" src="../js/libs/jquery.ui.datepicker-zh-CN.js" ></script>
		<script type="text/javascript" src="../js/index.js" ></script>
		<script type="text/javascript" src="../js/util.js" ></script>
		<script>
		var tableRowCount = $("table[id='goodsListTable']>tbody").children("tr").length;
		var totalPrice;
			$(function(){
				for(var i=0;i<tableRowCount;i++){
					updatePrice(i);
				}
				updateTotalPrice();
			});
			function checkInput(){
				var nameObj = document.getElementById("name");
				var phoneObj = document.getElementById("phone");
				if(chkInput(nameObj) && 
				chkInput(phoneObj) ){
					return true;
				}
			}
			function checkPayMethod(){
				var value = $('input:radio[name="payMethod"]:checked').val();
				if(value==null){
					alert("请选择付款方式");
					return false;
				}
				return true;
			}
			function submit(){
				if(checkInput() && checkPayMethod()){
					$('#form').submit();
				}
			}
			function updatePrice(index){
				var price = parseFloat($('#price_'+index).html().substring(1));
				var count = $('#input_'+index).html();
				var totalPrice = price * count;
				$('#totalPrice_'+index).html('￥'+toDecimal(totalPrice));
				//同时刷新总价
				updateTotalPrice();
			}
			function updateTotalPrice(){
				var totalPrice=0;
				for(var i=0;i<tableRowCount;i++){
					var onePrice = parseFloat($('#totalPrice_'+i).html().substring(1));
					totalPrice+= onePrice;
				}
				totalPrice = toDecimal(totalPrice);
				$('#totalPrice').html('￥'+ totalPrice);
			}
			function update(index){
				updatePrice(index);
			}
		</script>
		<!-- end scripts-->
	</body>
</html>
